package br.com.goldentrade.util.table;

import br.com.goldentrade.util.MoedaFormat;
import java.awt.Component;
import java.text.DecimalFormat;

import javax.swing.AbstractCellEditor;
import javax.swing.JFormattedTextField;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;




public class MoedaCellEditor extends AbstractCellEditor implements TableCellEditor {  
    
    /** 
     * classe para editar a celula com formato de moeda 
     * @requisicao [2389]
     */  
    private static final long serialVersionUID = 1L;  
    private JFormattedTextField moeda = null;  
    private DecimalFormat formatter = MoedaFormat.getInstance().getFormatoMoeda();  
      
    private JFormattedTextField getCell() {  
        if (moeda == null)  
            moeda = new JFormattedTextField(formatter);  
        return moeda;  
    }  
  
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {  
    	if(value instanceof Long)
    		value = new Double(value.toString());
    	getCell().setValue(value);
    	
        return getCell();  
    }  
  
    public Object getCellEditorValue() { 
    	Object value = getCell().getValue();
    	if(value instanceof Long)
    		value = new Double(value.toString());
        return value;
    }  
  
} 